Git Cheat Sheet is a comprehensive quick guide for learning Git concepts, from very basic to advanced levels. By this Git Cheat Sheet, our aim is to provide a handy reference tool for both beginners and experienced developers/DevOps engineers. This Git Cheat Sheet not only makes it easier for newcomers to get started but also serves as a refresher for experienced professionals.
Git Cheat Sheet
In this Git Cheat Sheet, we’ve covered all the basics to advanced Git commands that the developers required during the development and deployment process. Moreover, it is well-structured and categorized according to different use cases. It includes Git and GitHub, Git download, Git Configuration & Setup, Git commands, Git bash, Creating and Getting Git Projects, Git Snapshots, Branching and Merging in Git, Sharing and Updating in Git, Git Comparison, Managing History in Git, and more.
What is Git?Git is the free and open-source distributed version control systems that’s responsible for everything GitHub related that happens locally on your computer.
Understanding Version ControlVersion control, also known as source control, is the technique of tracking and managing changes to codes and these are the systems that are software tools that enable software teams to manage modifications to source code as time passes.
What is GitHub?GitHub is a widely-used Free-to-use cloud Storage platform with version control and many other essential features that specifically helps developers to manage and deploy their projects on GitHub.
Benefits of Using GitHistory Tracking: Git allows you to track every change made in your project, including: who made the change and when it was made.Collaboration: Multiple developers can be able work on the same project at the same time, and Git efficiently manages the merging of changes in code. Branching and Merging: Git enables developers to create branches to work on new features or bug fixes and later merge them back into the main codebase.Offline Work: Git works offline, which means you can commit changes and work on your project even without an internet connection.Learn Git Cheat Sheet (Basic to Advanced Concepts)
Git Installation CommandsGit Configuration & SetupInitializing a Repository Basic Git CommandsGit Commit (Updated Commands)Branching and MergingRemote RepositoriesGit ComparisonGit Managing HistoryWhy use Git?FAQs on Git Cheat Sheet Learn Git Cheat Sheet (Basic to Advanced Concepts)Git Installation CommandsHere are the Git installation commands for different operating systems:
Commands
Description
Git for Windows stand-alone installer. For more Details Read Here$ brew install gitInstall Git with Homebrew on Mac OS$ sudo port selfupdateInstall Git with MacPorts on Mac OS$ sudo apt-get install gitInstall Command for Linux$ git –versionShows the current version of your GitGit Configuration & SetupHere are Git configuration and setup commands:
Commands
Description
git config –global user.name “Your Name”Set your username globally.git config –global user.email “youremail@example.com”Set your email globally.git config –global color.ui auto –Set to display colored output in the terminalgit helpDisplay the main help documentation, showing a list of commonly used Git commands.Initializing a RepositoryHere are the Git initializing a repository commands:
Commands
Description
git initInitializes a new Git repository in the current directory.git init Creates a new Git repository in the specified directory.git clone this Clones a repository from a remote server to your local machine.git clone –branch Clones a specific branch from a repository.Basic Git CommandsHere are some basic Git commands:
Commands
Description
git add Adds a specific file to the staging area.git add . or git add –allAdds all modified and new files to the staging area.git statusShows the current state of your repository, including tracked and untracked files, modified files, and branch information.git status –ignoredDisplays ignored files in addition to the regular status output.git diffShows the changes between the working directory and the staging area (index).git diff Displays the differences between two commits.git diff –staged or git diff –cachedDisplays the changes between the staging area (index) and the last commit.git diff HEADDisplay the difference between the current directory and the last commitgit commitCreates a new commit with the changes in the staging area and opens the default text editor for adding a commit message.git commit -m “” or git commit –message “”Creates a new commit with the changes in the staging area and specifies the commit message inline.git commit -a or git commit –allCommits all modified and deleted files in the repository without explicitly using git add to stage the changes.git notes addCreates a new note and associates it with an object (commit, tag, etc.).git restore Restores the file in the working directory to its state in the last commit.git reset Moves the branch pointer to a specified commit, resetting the staging area and the working directory to match the specified commit.git reset –soft Moves the branch pointer to a specified commit, preserving the changes in the staging area and the working directory.git reset –hard Moves the branch pointer to a specified commit, discarding all changes in the staging area and the working directory, effectively resetting the repository to the specified commit.git rm Removes a file from both the working directory and the repository, staging the deletion.git mvMoves or renames a file or directory in your Git repository.Also, check: Basic Git Commands with Examples
Git Commit (Updated Commands)Here are some of the updated commands for Git commit:
Commands
Description
git commit -m “feat: message”Create a new commit in a Git repository with a specific message to indicate a new feature commit in the repository.git commit -m “fix: message”Create a new commit in a Git repository with a specific message to fix the bugs in codebasesgit commit -m “chore: message”Create a new commit in a Git repository with a specific message to show routine tasks or maintenance.git commit -m “refactor: message”Create a new commit in a Git repository with a specific message to change the code base and improve the structure.git commit -m “docs: message”Create a new commit in a Git repository with a specific message to change the documentation.git commit -m “style: message”Create a new commit in a Git repository with a specific message to change the styling and formatting of the codebase.git commit -m “test: message”Create a new commit in a Git repository with a specific message to indicate test-related changes.git commit -m “perf: message”Create a new commit in a Git repository with a specific message to indicate performance-related changes.git commit -m “ci: message”Create a new commit in a Git repository with a specific message to indicate the continuous integration (CI) system-related changes.git commit -m “build: message”Create a new commit in a Git repository with a specific message to indicate the changes related to the build process.git commit -m “revert: message”Create a new commit in a Git repository with a specific message to indicate the changes related to revert a previous commit.Branching and MergingHere are some Git branching and merging commands:
Commands
Description
git branchLists all branches in the repository.git branch Creates a new branch with the specified name.git branch -d Deletes the specified branch.git branch -aLists all local and remote branches.git branch -rLists all remote branches.git checkout Switches to the specified branch.git checkout -b Creates a new branch and switches to it.git checkout — Discards changes made to the specified file and revert it to the version in the last commit.git merge Merges the specified branch into the current branch.git logDisplays the commit history of the current branch.git log